<template>
    <Layout>
        <Form ref="form1" :model="form1" :label-width="120">
            <Row class="query-form" style="padding-top: 15px">
                <Col span="8">
                    <FormItem label="企业名称：">
                        <cascaderDom ref="childOrg" @setOrgInfo="setOrgId" @setOrgname="setOrgName"
                                     :orgTree="true" :root-org-id="companyId"></cascaderDom>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="审计年度：">
                         <DatePicker type="year" v-model="form1.adtYear" style="width: 100%"></DatePicker>
                    </FormItem>
                </Col>
                <Col span="8">
                    <Button @click="reset" class="ivu-btn-reset">重置</Button>
                    <Button class="ivu-btn-query" icon="md-search" @click="query()">查询</Button>
                </Col>
            </Row>
        </Form>
        <Table ref='table' :loading="loading" size="small" :height="tableHeight" class="no-add-table"
               no-data-text="没有查询到相关数据!"
               highlight-row stripe border :columns="columns1" width="100%" :data="dataTable">
        </Table>
        <Row style="margin-right:10px;">
            <Col span="24">
                <Page :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange"
                      style="float: right" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray"
                      show-total show-sizer show-elevator/>
            </Col>
        </Row>

    </Layout>
</template>

<script>
    import {Api} from '@/api/index.js' 
    import {sessionStorage} from '@/common/cacheUtils.js';
    var cascaderDom = () => import('@/components/cascader-dom.vue');

    export default {
        components: {cascaderDom},
        name: "riskStatical",
        data() {
            return {
                date: ['', ''],
                loading: false, tableHeight: '',
                form1: {
                    auditedOrgId: '',
                },
                pageSizeArray: [10, 20, 50],
                pagedata: {
                    total: 0,
                    pageSize: 10,
                    currentPage: 1,
                },
                companyId: sessionStorage('userId').getObject('userId').companyId,
                dataTable: [],
                columns1: [
                    {
                        title: "序号",
                        width: 80,
                        align: "center",
                        fixed: 'left',
                        render: (h, params) => {
                            return h('span', params.index + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
                        }
                    },
                    {
                        minWidth: 300,
                        title: '审计单位名称',
                        align: 'center',
						fixed: 'left',
                        key: 'auditedOrgName',
                    },
                    {
                        minWidth: 200,
                        title: '审计任务名称',
                        align: 'center',
                        key: 'missionName',
                    },
                    {
                        minWidth: 100,
                        title: '审计年度',
                        align: 'center',
                        key: 'adtYear',
                    },
                    {
                        minWidth: 100,
                        title: '审计得分',
                        align: 'center',
                        key: 'appraiseScore',
                    },
                    {
                        minWidth: 150,
                        title: '审计问题',
                        align: 'center',
                        children: [
                            {
                                title: '验证通过',
                                key: 'verifyPros',
                                align: 'center',
                                minWidth: 100
                            }, {
                                title: '验证未通过',
                                key: 'unverifyPros',
                                align: 'center',
                                minWidth: 100
                            }
                        ]
                    },
                ],
                model1: false,
                model2: false,
                buttonDisabled: false,
                InputData: {},
            }
        },
        mounted() {
            this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 145;
            this.query()

        },
        methods: {


            setOrgId(data) {
                this.form1.auditedOrgId = data[data.length - 1];
            },
            setOrgName(data) {
                this.form1.orgName = data;
            },
            formatDate(date, fmt) {
                if (/(y+)/.test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
                }
                let o = {
                    'M+': date.getMonth() + 1,
                    'd+': date.getDate(),
                    'h+': date.getHours(),
                    'm+': date.getMinutes(),
                    's+': date.getSeconds()
                };
                for (let k in o) {
                    if (new RegExp(`(${k})`).test(fmt)) {
                        let str = o[k] + '';
                        fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
                    }
                }
                return fmt;
            },
            padLeftZero(str) {
                return ('00' + str).substr(str.length);
            },
            query() {
                this.loading = true;

                let data = {
                    startPage: this.pagedata.currentPage,
                    size: this.pagedata.pageSize,
                    auditedOrgId: sessionStorage('userId').getObject('userId').companyId
                };
                if (this.form1.auditedOrgId) {
                    //this.form1.orgId = sessionStorage('userId').getObject('userId').companyId
                    data.auditedOrgId = this.form1.auditedOrgId
                }
                if(this.form1.adtYear) {
                    data.adtYear = new Date(this.form1.adtYear).getFullYear()
                }
                //this.form1.adtYear = new Date(this.form1.adtYear).getFullYear()
                //data = Object.assign(data, JSON.parse(JSON.stringify(this.form1)));
                let url = Api.adtStatistics
                this.$http.get(url, {params: data}).then((res) => {
                    //console.log('11111',res.data);
                    this.dataTable = res.data.data;
                    this.pagedata.total = res.data.totalSize;
                    this.loading = false;
                }).catch(e => {
                    this.$Message.error("数据获取失败")
                })
            },
            reset() {
                this.form1 = {
                    orgId: '',
                    year: '',
                    yearDate: ''
                }
                this.date = ['', ''];
                this.$refs.childOrg.resetCurrentOrg();
            },
            pageChange(pageNum) {
                this.pagedata.currentPage = pageNum;
                this.query();
            },
            pageSizeChange(pageSize) {
                this.pagedata.pageSize = pageSize;
                this.query();
            },
        }
    }
</script>

<style lang='css' scoped>
    @import '../../../index.css';
</style>